package com.amigo.online.provider.user.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.amigo.online.common.core.mybatis.MyMapper;
import com.amigo.online.provider.user.model.entity.InviteCodeRecord;

@Mapper
@Component
public interface InviteCodeRecordMapper extends MyMapper<InviteCodeRecord> {

    @Select("SELECT count(*) FROM invite_code_record_tbl "
            + "WHERE CODE = ( SELECT CODE FROM invite_code_tbl WHERE user_id = #{userId} AND deleted = 0 ) "
            + "and deleted = 0")
    int getTotalInviteAmount(Long userId);

    @Select("SELECT count(*) FROM invite_code_record_tbl "
            + "WHERE CODE = #{code} and deleted = 0")
    int getTotalInviteAmountByCode(String code);

    @Select("select count(*) FROM invite_code_record_tbl WHERE looker_user_id = #{lookerUserId} AND code = #{code} AND deleted = 0")
    int getCount(@Param("lookerUserId") Long lookerUserId,@Param("code") String code);

    @Select("SELECT count(*) FROM invite_code_record_tbl "
            + "WHERE CODE = #{code} and deleted = 0 and created_time <= #{zero} and created_time >= #{l}")
    Integer selectToday(String code, long zero, long l);

    @Select("SELECT count(*) FROM invite_code_record_tbl "
            + "WHERE CODE = #{code} and deleted = 0 and created_time < #{zero}")
    Integer selectTotal(String code, long zero, long l);

}
